package com.niit.controller;




import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.niit.entity.CourseDTO;



@RestController
public class Green {
	private Random random = new Random();
	@Resource(name="butterServiceImpl")
	private ButterService butterService;
	@Resource
	private MilkService milkService;
	@RequestMapping(value="/Monday")
	public String justTest(){
		return "no meaning at all";
	}
	
	@RequestMapping(value="/Thuesday",method=RequestMethod.GET)
	public String allWays(@RequestParam String studentName){
		if (studentName == null) {
			return"please get with studentName";
		}
		return butterService.rubickServe(studentName);
	}
	//redis test
	@RequestMapping(value="/Wendsday",method=RequestMethod.GET)
	public String anyWay(@RequestParam String userToken){
		if (milkService.get(userToken)==null) {
			milkService.set(userToken,random.nextInt(1500)+"s");
		}
		return milkService.get(userToken);
	}
	@RequestMapping(value="/Thursday",method=RequestMethod.GET)
	public List<String> ownWay(@RequestParam String studentName){
		//List<CourseDTO> first=butterService.provideCourse(studentName);
		//return first;
		if (milkService.getCourse(studentName).size()==0) {
			List<CourseDTO> first=butterService.provideCourse(studentName);
			System.out.println(first);
			List<String> second = new ArrayList<>();
			for(CourseDTO courseDTO: first){
				second.add(courseDTO.getCourseName());
			}
		
			milkService.setCourse(studentName, second);
		
		}
		
		return milkService.getCourse(studentName);
		
	}
	@RequestMapping(value="/Friday",method=RequestMethod.GET)
 //   @PutMapping(value="/Friday")
	public String saveWay(@RequestParam String studentName,
			@RequestParam String course){
    	
    	butterService.saveChoosenClass(studentName,course);
    
		return "success";
	}

}
